﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using SIMS.Utils.Personal;
using SIMS.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace SIMS.ViewModels
{
    public class HeaderViewModel : BindableBase
    {
        private UserInfo userInfo;
        private IDialogService _dialogService;

        public UserInfo UserInfo { get { return userInfo; } set { SetProperty(ref userInfo, value); } }

        public HeaderViewModel(IDialogService dialogService)
        {
            userInfo= new UserInfo();
            this._dialogService = dialogService;
        }

        #region 事件

        private DelegateCommand loadedCommand;

        public DelegateCommand LoadedCommand
        {
            get
            {
                if (loadedCommand == null)
                {
                    loadedCommand = new DelegateCommand(Loaded);
                }
                return loadedCommand;
            }
        }



        private DelegateCommand loginoutCommand;

        public DelegateCommand LoginoutCommand
        {
            get
            {
                if (loginoutCommand == null)
                {
                    loginoutCommand = new DelegateCommand(Loginout);
                }
                return loginoutCommand;
            }
        }

        private void Loginout()
        {
            MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
            mainWindow.Close();


        }

        private void LoginCallback(IDialogResult dialogResult)
        {
            if (dialogResult.Result != ButtonResult.OK)
            {
                Application.Current.Shutdown();
            }
        }

        private void Loaded()
        {
            InitInfo();
        }

        private void InitInfo() {
            this.UserInfo = UserInfo.Instance;
        }

        #endregion
    }
}
